﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Common.Msg
{
    public class DoResult<T>
    {
        public DoResult()
        {
            this.EnumCode = EnumCode.Error;
            this.Msg = "";
            this.Data = default(T);
        }

        /// <summary>
        /// 操作状态
        /// </summary>
        [XmlElement("Status")]
        public bool Status
        {
            get { return this.EnumCode == EnumCode.Success; }
        }
        /// <summary>
        /// 编码枚举
        /// </summary>
        [XmlElement("EnumCode")]
        public EnumCode EnumCode { get; set; }
        /// <summary>
        /// 枚举编码
        /// </summary>
        [XmlElement("SysCode")]
        public string SysCode
        {
            get { return ((int)EnumCode).ToString(); }
        }
        /// <summary>
        /// 枚举提示消息
        /// </summary>
        [XmlElement("SysMsg")]
        public string SysMsg
        {
            get { return EnumCode.ToString(); }
        }
        /// <summary>
        /// 操作失败时的错误提示消息
        /// </summary>
        [XmlElement("Msg")]
        public string Msg { get; set; }
        /// <summary>
        /// 数据存储备用字段
        /// </summary>
        [XmlElement("Data")]
        public T Data { get; set; }

        /// <summary>
        /// 将自己转换成JSON数据字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Common.Serialize.JsonHelper.ToJson(this);
        }
    }
    public enum EnumCode
    {
        Error = 0,
        Success = 1
    }
}
